﻿using Microsoft.Extensions.DependencyInjection;
using System;

namespace Gaea.CodeFirst.MySql
{
    public static class GaeaCodeFirstMySqlExtension
    {
        public static IServiceCollection AddCodeFirst(this IServiceCollection serviceCollection, ITable table = null)
        {
            serviceCollection.AddSingleton<ITable>(table ?? new MySqlOperateTable());
            serviceCollection.AddSingleton<GaeaCodeFirstBasicAdapter>();
            return serviceCollection;
        }

        public static IServiceProvider UseCodeFirst(this IServiceProvider serviceProvider)
        {
            var codeFirstPower = serviceProvider.GetRequiredService<GaeaCodeFirstBasicAdapter>();
            codeFirstPower.CompareTable(AppDomain.CurrentDomain.GetAssemblies());
            return serviceProvider;
        }
    }
}
